/**********************************************************************
 * Project : WoWGuildRoster (http://www.codeplex.com/WowGuildRoster/)
 * Module  : DotNetWarcraft.WoWGuildRoster.Business.DataLoad
 **********************************************************************
 * 
 * 
 * 
 **********************************************************************
 * License : All code is subject to licensing terms per the Microsoft
 *   Permissive License (Ms-PL) v1.1. For full license information,
 *   refer to the packaged license.txt file.
 **********************************************************************
 * Revision History:
 * -----------------
 * 2007-08-05 -- Cliff Simpkins: Initial Version with properties and constructors
 **********************************************************************
 */
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

using DotNetWarcraft.Common;


namespace DotNetWarcraft.WoWGuildRoster.Business {
  /// <summary>
  /// Information about a particular information load/batch that was processed into
  ///   the database.
  /// </summary>
  public class DataLoad {
  #region Public Properties
    public int Load_ID {
      get;
      set;
    }
    public int Roster_ID {
      get;
      set;
    }

    public int LoadType {
      get;
      set;
    }
    public WGR_LoadTypes LoadType_Enum {
      get {
        return WGRConstants.LoadType_Enum(this.LoadType);
      }
      set {
        this.LoadType = WGRConstants.LoadType_Int(value);
      }
    }
    public int LoadStatus {
      get;
      set;
    }
    public WGR_LoadStatus LoadStatus_Enum {
      get {
        return WGRConstants.LoadStatus_Enum(this.LoadStatus);
      }
      set {
        this.LoadStatus = WGRConstants.LoadStatus_Int(value);
      }
    }
    public int LastCharIdLoaded {
      get;
      set;
    }

    public String Load_StartedBy {
      get;
      set;
    }
    public String Load_Source {
      get;
      set;
    }

    public DateTime LoadTime_Started {
      get;
      set;
    }
    public DateTime LoadTime_Ended {
      get;
      set;
    }

    public int LoadCount_Adds {
      get;
      set;
    }
    public int LoadCount_Updates {
      get;
      set;
    }
    public int LoadCount_Skips {
      get;
      set;
    }
    public int LoadCount_Errors {
      get;
      set;
    }
  #endregion

  #region Constructors
    public DataLoad() : base() {
      this.Load_ID = -1;
      this.Roster_ID = -1;

      this.LoadType_Enum = WGR_LoadTypes.Unknown;
      this.LoadStatus_Enum = WGR_LoadStatus.Uninitialized;
      this.LastCharIdLoaded = -1;

      this.Load_StartedBy = "";
      this.Load_Source = "";

      this.LoadTime_Started = DateTime.MinValue;
      this.LoadTime_Ended = DateTime.MinValue;

      this.LoadCount_Adds = 0;
      this.LoadCount_Updates = 0;
      this.LoadCount_Skips = 0;
      this.LoadCount_Errors = 0;
    }
    public DataLoad(int rosterID, String loadStartedBy, String loadSource, DateTime timeStarted)
      : this() {
      this.Roster_ID = rosterID;

      this.Load_StartedBy = loadStartedBy;
      this.Load_Source = loadSource;

      this.LoadTime_Started = timeStarted;
    }
    public DataLoad(int rosterID, String loadStartedBy, String loadSource, DateTime timeStarted, DateTime timeEnded, int cAdds, int cUpdates, int cSkips, int cErrors)
      : this() {
      this.Roster_ID = rosterID;

      this.Load_StartedBy = loadStartedBy;
      this.Load_Source = loadSource;

      this.LoadTime_Started = timeStarted;
      this.LoadTime_Ended = timeEnded;

      this.LoadCount_Adds = cAdds;
      this.LoadCount_Updates = cUpdates;
      this.LoadCount_Skips = cSkips;
      this.LoadCount_Errors = cErrors;

    }

    public DataLoad(DataRow rosterSrc)
      : base() {
      this.Load_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["load_id"]);
      this.Roster_ID = SqlDataUtils.RetrieveDbInt(rosterSrc["roster_id"]);

      this.LoadType = SqlDataUtils.RetrieveDbInt(rosterSrc["load_type"]);
      this.LoadStatus = SqlDataUtils.RetrieveDbInt(rosterSrc["load_status"]);
      this.LastCharIdLoaded = SqlDataUtils.RetrieveDbInt(rosterSrc["last_char_id"]);

      this.Load_StartedBy = SqlDataUtils.RetrieveDbString(rosterSrc["load_started_by"]);
      this.Load_Source = SqlDataUtils.RetrieveDbString(rosterSrc["load_source"]);

      this.LoadTime_Started = SqlDataUtils.RetrieveDbDate(rosterSrc["load_started"]);
      this.LoadTime_Ended = SqlDataUtils.RetrieveDbDate(rosterSrc["load_ended"]);

      this.LoadCount_Adds = SqlDataUtils.RetrieveDbInt(rosterSrc["load_count_adds"]);
      this.LoadCount_Updates = SqlDataUtils.RetrieveDbInt(rosterSrc["load_count_updates"]);
      this.LoadCount_Skips = SqlDataUtils.RetrieveDbInt(rosterSrc["load_count_skips"]);
      this.LoadCount_Errors = SqlDataUtils.RetrieveDbInt(rosterSrc["load_count_errors"]);
    }
  #endregion

  #region Interpreted Properties
    public String Roster_ID_String {
      get {
        if (this.Roster_ID < 0) {
          return "N/A";
        } else {
          return this.Roster_ID.ToString();
        }
      }
    }
    public String LoadStatus_String {
      get {
        return WGRConstants.LoadStatus_String(this.LoadStatus_Enum);
      }
    }
    public String LoadType_String {
      get {
        return WGRConstants.LoadType_String(this.LoadType_Enum);
      }
    }
  #endregion
  #region Public Methods
    public void MarkCompleted(DateTime timeEnded, int cAdds, int cUpdates, int cSkips, int cErrors) {
      this.LoadTime_Ended = timeEnded;

      this.LoadCount_Adds = cAdds;
      this.LoadCount_Updates = cUpdates;
      this.LoadCount_Skips = cSkips;
      this.LoadCount_Errors = cErrors;
    }
  #endregion
  }
}
